package ui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/*管理员功能选择*/
/*管理员选择管理四张表中的哪个表*/
public class LibrarianOp extends JFrame implements ActionListener {
	private JButton bb1;
	private JButton bb2;
	private JButton bb3;
	private JButton bb4;
	
	private JButton rb1;
	private JButton rb2;
	private JButton rb3;
	private JButton rb4;
	
	private JButton lb1;
	private JButton lb2;
	private JButton lb3;
	private JButton lb4;
	
	private JButton bsb1;
	
	private JButton returnbutton;
	
	public LibrarianOp() {
		JFrame jFrame = new JFrame("管理员功能选择");
		//JPanel jpc = new JPanel();// 默认流式布局
		jFrame.setLayout(new BorderLayout());
		//jFrame.setSize(300, 200);
		JPanel jp0 = new JPanel(new GridLayout(2, 2, 10, 10));
		jp0.setBorder(BorderFactory.createTitledBorder("功能面板"));
		JPanel jp1 = new JPanel(new GridLayout(4, 1, 10, 5));//设置新面板
		// 网格布局GridLayout(int rows, int columns, int hgap, int vgap)行数，列数，组件水平间距，垂直间距
		jp1.setBorder(BorderFactory.createTitledBorder("书籍信息管理"));
		JPanel jp2 = new JPanel(new GridLayout(4, 1, 10, 5));
		jp2.setBorder(BorderFactory.createTitledBorder("读者信息管理"));
		JPanel jp3 = new JPanel(new GridLayout(4, 1, 10, 5));
		jp3.setBorder(BorderFactory.createTitledBorder("管理员信息管理"));
		JPanel jp4 = new JPanel(new GridLayout(4, 1, 10, 5));
		jp4.setBorder(BorderFactory.createTitledBorder("书籍借阅系统管理"));

		jp0.add(jp1);
		jp0.add(jp2);
		jp0.add(jp3);
		jp0.add(jp4);
		
		//this.setLayout(new FlowLayout());
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

		setTitle("管理员功能选择界面");
		setSize(420, 420);
		setLocationRelativeTo(null);
		

		// 监听右上角的退出按钮
		this.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent windowEvent) {
				System.exit(0);
			}
		});
		 bb1 = new JButton("查询书籍");
		 bb2 = new JButton("增加书籍");
		 bb3 = new JButton("删除书籍");
		 bb4 = new JButton("修改书籍");
		
		 rb1 = new JButton("查询读者信息");
		 rb2 = new JButton("增加读者信息");
		 rb3 = new JButton("删除读者信息");
		 rb4 = new JButton("修改读者信息");
		
		 lb1 = new JButton("查询管理员信息");
		 lb2 = new JButton("增加管理员信息");
		 lb3 = new JButton("删除管理员信息");
		 lb4 = new JButton("修改管理员信息");
		
		 bsb1 = new JButton("查询借阅信息");
		
		jp1.add(bb1);
		jp1.add(bb2);
		jp1.add(bb3);
		jp1.add(bb4);
		
		jp2.add(rb1);
		jp2.add(rb2);
		jp2.add(rb3);
		jp2.add(rb4);
		
		jp3.add(lb1);
		jp3.add(lb2);
		jp3.add(lb3);
		jp3.add(lb4);
		
		jp4.add(bsb1);
		
		JPanel jp5 = new JPanel();
		returnbutton = new JButton("退出登录");
		returnbutton.addActionListener(this);
		jp5.add(returnbutton);
		add(jp5, BorderLayout.SOUTH);
		getContentPane().add(jp0,BorderLayout.CENTER);

		bb1.addActionListener(this);
		bb2.addActionListener(this);
		bb3.addActionListener(this);
		bb4.addActionListener(this);
		
		rb1.addActionListener(this);
		rb2.addActionListener(this);
		rb3.addActionListener(this);
		rb4.addActionListener(this);
		
		lb1.addActionListener(this);
		lb2.addActionListener(this);
		lb3.addActionListener(this);
		lb4.addActionListener(this);
		
		bsb1.addActionListener(this);

		this.setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		BookOther BookOther = new BookOther(); 
		ReaderOther ReaderOther = new ReaderOther();
		LibrarianOther LibrarianOther = new LibrarianOther();
		if (e.getSource() == bb1) {//查询书籍
			this.dispose();
			new BookSearchButtonlibrarian();
		}else if (e.getSource() == bb2) {//增加书籍
			this.dispose();
			BookOther.AddBook();
		}else if (e.getSource() == bb3) {//删除书籍
			this.dispose();
			BookOther.DeleteBook();
		}else if (e.getSource() == bb4) {//修改书籍
			this.dispose();
			BookOther.UpdateBookButton();
		}else if (e.getSource() == rb1) {
			this.dispose();
			new ReaderSearchButtons();
		}else if (e.getSource() == rb2) {
			this.dispose();
			ReaderOther.AddReader();
		}else if (e.getSource() == rb3) {
			this.dispose();
			ReaderOther.DeleteReader();
		}else if (e.getSource() == rb4) {
			this.dispose();
			ReaderOther.UpdateReaderButton();
		}else if (e.getSource() == lb1) {
			this.dispose();
			new LibrarianSearchButtons();
		}else if (e.getSource() == lb2) {
			this.dispose();
			LibrarianOther.AddLibrarian();
		}else if (e.getSource() == lb3) {
			this.dispose();
			LibrarianOther.DeleteLibrarian();
		}else if (e.getSource() == lb4) {
			this.dispose();
			LibrarianOther.UpdateLibrarianButton();
		}else if (e.getSource() == bsb1) {//查询借阅记录全表
			this.dispose();
			new RecordSearchButtons();
		} else if (e.getSource() == returnbutton) {//查询借阅记录全表
			this.dispose();
			new Bind();
		} 
	}

}
